import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/add_mains_electricity_price/views/peak_and_plateau_time_widget.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/elec_price_title_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

class MainsHoursSetWidgets extends StatelessWidget {
  final List<dynamic> peakAndPlateauList;
  final Function() addCallBack;
  final Function(int index) deleteCallBack;
  final Function() dateCallBack;
  final Function() typeClickCallBack;
  const MainsHoursSetWidgets(this.peakAndPlateauList, this.addCallBack, this.deleteCallBack,
      this.dateCallBack,this.typeClickCallBack,
      {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return  Container(
        clipBehavior: Clip.hardEdge,
        margin: const EdgeInsets.only(left: 16,right: 16),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          color: Colors.white,
        ),

        height: peakAndPlateauList.length * 100 + 58 + 50,
        child: Column(
          children: [
            ElecPriceTitleWidget(ResKey.peakValleyPeriods.tr),
            ListView.builder(
              padding: EdgeInsets.zero,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (BuildContext context, int index) =>
                  PeakAndPlateauTimeWidget(context,'${ResKey.siteSettingElectricityTimeStage.tr}${index + 1}',peakAndPlateauList[index]['type'].toString(),
                    peakAndPlateauList[index]['intervalStartTime'],
                    peakAndPlateauList[index]['intervalEndTime'],(startDateTime,endDateTime){
                    if(startDateTime == '23:59'){
                      startDateTime = '24:00';
                    }
                    if(endDateTime == '23:59'){
                      endDateTime = '24:00';
                    }
                      peakAndPlateauList[index] = {
                        'intervalStartTime':startDateTime,
                        'intervalEndTime':endDateTime,
                        'type':0
                      };
                      // update();

                      dateCallBack();
                    },(){
                      // deletePeakAndPlateauListList(i);
                      deleteCallBack(index);
                    },(String type){
                      peakAndPlateauList[index]['type'] = type;
                      typeClickCallBack();
                    },isDelete: true,),
              itemCount: peakAndPlateauList.length,
            ),
            Container(
              height: 0.5,
              color: Colour.dividerColor,
              margin: EdgeInsets.only(left: 16.w, right: 16.w),
            ),
            GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  addCallBack();
                },
                child: SizedBox(
                  height: 49,
                  child: Row(
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: 16, right: 16),
                        child: Image.asset(
                          'assets/images/site_elec_price_add.png',
                          height: 18,
                          width: 18,
                        ),
                      ),
                      Text(
                        ResKey.siteSettingElectricityAddStage.tr,
                        style: ytTextStyle(
                            fontWeight: FontWeight.normal,
                            color: Colour.primaryColor,
                            fontSize: 14),
                      ),
                    ],
                  ),
                ))
          ],
        ));
  }
  
}
